#!/usr/local/bin/python3
# -*- coding: utf-8 -*-
"""
@File  : charts.py
@Author: different && 道阻且长,行则将至 行而不辍,未来可期
@Date  : 2021/08/04
@Desc  : 模型

"""

from sqlalchemy import func, text

from apps.models.association import user_table
from apps.models.cross_group import CrossAttr
from apps.models.user import User
from expand import db


class DataSourceTitle(db.Model):
    __tablename__ = 'data_source_title'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(100), comment='标题')
    filename = db.Column(db.String(100), comment='文件名')
    upload_user = db.Column(db.String(50), comment='上传者用户名')
    is_delete = db.Column(db.Boolean, default=False, comment='是否删除')
    rel_content = db.relationship('DataSourceContent', backref=db.backref('rel_title'), cascade='all')
    table_attr = db.relationship(CrossAttr, cascade='all')
    create_time = db.Column(db.DateTime(timezone=True), server_default=func.now(), comment='创建时间')
    users = db.relationship(User, secondary=user_table, back_populates="tables", cascade='all')

    def __str__(self):
        return self.title


class DataSourceContent(db.Model):
    __tablename__ = 'data_source_content'
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    asin = db.Column(db.String(20), comment='asin')
    site = db.Column(db.String(10), comment='站点')
    product_link = db.Column(db.String(200), comment='产品链接')
    image_url = db.Column(db.String(200), comment='主图地址')
    video_link = db.Column(db.String(200), comment='视频链接')
    page_num = db.Column(db.String(10), comment='所在页数')
    page_rank = db.Column(db.String(10), comment='页面排名')
    ad_page_num = db.Column(db.String(10), comment='广告所在页数')
    ad_page_rank = db.Column(db.String(10), comment='广告页面排名')
    price = db.Column(db.Float(precision="10,2"), comment='价格')
    variants = db.Column(db.Integer, comment='变体')
    follow_up = db.Column(db.Integer, comment='跟卖数')
    aPlus = db.Column(db.String(10), comment='是否是A+用户')
    shelf_date = db.Column(db.Date, comment='上架日期')
    big_category = db.Column(db.String(100), comment='大类目')
    big_category_rank = db.Column(db.Integer, comment='大类目排名')
    sub_category_1 = db.Column(db.String(100), comment='小类目1')
    sub_category_1_rank = db.Column(db.Integer, comment='小类目1排名')
    sub_category_2 = db.Column(db.String(100), comment='小类目2')
    sub_category_2_rank = db.Column(db.Integer, comment='小类目2排名')
    rank_days_30 = db.Column(db.Integer, comment='近30天排名')
    ratings = db.Column(db.Integer, comment='评分数')
    rating = db.Column(db.Float, comment='评分', server_default=text('0'))
    reviews = db.Column(db.Integer, comment='reviews')
    critical = db.Column(db.Integer, comment='Critical')
    vp_comments = db.Column(db.Integer, comment='VP评论数')
    qa_num = db.Column(db.Integer, comment='QA数')
    brand = db.Column(db.String(100), comment='品牌')
    seller_type = db.Column(db.String(10), comment='卖家类型')
    store_name = db.Column(db.String(100), comment='店铺名称')
    feedback_num = db.Column(db.Integer, comment='feedback数')
    feedback_rate = db.Column(db.Float, comment='feedback差评率')
    sale = db.Column(db.Integer, comment='销量')
    attr = db.Column(db.String(255), comment='属性')
    table_id = db.Column(db.Integer, db.ForeignKey('data_source_title.id'))
    create_time = db.Column(db.DateTime(timezone=True), server_default=func.now(), comment='创建时间')
